package com.lpf.morphia;

import cn.hutool.json.JSONUtil;
import com.lpf.morphia.entity.Member;
import com.mongodb.MongoClient;
import org.mongodb.morphia.Datastore;
import org.mongodb.morphia.Key;
import org.mongodb.morphia.Morphia;

/**
 * Morphia, MongoDB界的一个ORM鼻祖
 * 后来又有了MongoTemplate
 */
public class MorphiaTest {

    public static void main(String[] args) {

        final Morphia morphia = new Morphia();
        Datastore ds = morphia.createDatastore(new MongoClient("localhost", 27017), "testDB_Java_03");

        Member member = new Member();
        member.setName("wt");
        member.setAge(18);
        member.setAddr("浙江杭州西湖区");

        Key<Member> key = ds.save(member);

        System.out.println(key.getId());
        System.out.println(JSONUtil.toJsonPrettyStr(key));
    }
}
